import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue'

Vue.use(VueRouter)

const routes = [

  {
    path:'/',
    redirect:'/login'
  },
  {
    path:'/login',
    name:'Login',
    component:()=>import('../components/Login.vue')

  },

  {
    path:'/home',
    name:'Home',
    component:()=>import('../components/Home.vue'),
    redirect:'/home/weicome',

    children: [
      {
        path: 'weicome',
        name: 'Weicome',
        component: ()=>import('../components/Weicome.vue')
      },
      {
        path: 'users',
        name: 'Users',
        component: ()=>import('../components/user/User.vue')
      },
      {
        path: 'rights',
        name: 'Rights',
        component: ()=>import('../components/power/Rights.vue')
      },
      {

        path: 'roles',
        name: 'Roles',
        component: ()=>import('../components/power/Roles.vue')
      },  {

        path: 'categories',
        name: 'Categories',
        component: ()=>import('../components/goods/cate.vue')
      },
      {

        path: 'params',
        name: 'Params',
        component: ()=>import('../components/goods/params.vue')
      },
      {
        
        path: 'goods',
        name: 'Goods',
        component: ()=>import('../components/goods/List.vue')
       
      },
      {

        path: '/goods/add',
        name: 'Add',
        component: ()=>import('../components/goods/Add.vue')
       
      },
    ]
  }
]

const router = new VueRouter({
  routes
})

//路由导航守卫

router.beforeEach((to, from, next) => {
  /* must call `next` */
  if(to.path == '/login')return next()

  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')

  next()
  
});
export default router
